package com.paperobot.action.Interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.paperobot.model.Admin;

public class AuthorityInterceptor extends AbstractInterceptor {

	private static final long serialVersionUID = 5920681106835179817L;
	protected final Logger logger = LoggerFactory.getLogger(getClass());
	
	public String intercept(ActionInvocation invocation) throws Exception {
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session = request.getSession(true);
		Admin loginUser = (Admin) session.getAttribute("loginUser");

		if (loginUser != null && !loginUser.getUserName().equals(""))
			return invocation.invoke();
		else {
			logger.info("用户未登录，请登录！");
			return "login";
		}
	
	}

}
